package com.example.busshop.controller;

import com.example.busshop.common.controller.LogicController;
import com.example.busshop.common.service.LogicService;
import com.example.busshop.config.R;
import com.example.busshop.dao.ShopDao;
import com.example.busshop.entity.Item;
import com.example.busshop.entity.Order;
import com.example.busshop.entity.Shop;
import com.example.busshop.entity.ShopItem;
import com.example.busshop.service.OrderService;
import com.example.busshop.service.ShopService;
import jdk.jfr.Frequency;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.annotation.RequestScope;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

@RestController
@RequestMapping("/shop")
public class ShopController extends LogicController<ShopService, ShopDao,Shop,Long>{
    public ShopController(@Autowired ShopService shopService) {
        super(shopService);
    }
    @Resource
    ShopService shopService;
    @Resource
    OrderService orderService;
    @PostMapping("/addItem")
    public Item addItem(@RequestBody Item item, @RequestParam Long Id){
        return shopService.addItem(item,Id);
    }
    @PostMapping("/newItem")
    public ShopItem newItem(@RequestParam Long Id, @RequestBody Item item){
         return shopService.newItem(Id,item);
    }
    @RequestMapping("/queren")
    public R QueRen(@RequestParam Long Id){
        return shopService.QueRen(Id);
    }
    @RequestMapping("/refunds")
    public Object refunds(@RequestParam Long Id){
       R res= shopService.Refund(Id);
       Map<String,Object> map=new HashMap<>();
       Order order=orderService.GET(Id);
       map.put("message",res);
       map.put("shop",order.getShop());
       return map;

    }
    @GetMapping("/allOrder")
    public Set<Order> allOrder(@RequestParam Long Id){
        return shopService.allOrder(Id);
    }
    @RequestMapping ("/allItems")
    public Set<ShopItem> shopItemAll(@RequestParam Long Id){
        return shopService.allItems(Id);
    }
}
